import {
	Component
} from 'react';
import {
	Tab,
	Button,
	ScrollList,
	Group,
	Boxs,
	Avatar,
	Badge,
	Popup,
	Dialog,
	Toast,
	SearchBar
} from 'saltui';
const {
	IconButton
} = Button;
const {
	HBox,
	Box,
	VBox
} = Boxs;

import {
	urlPrefix,
	URLS,
	nodataIcon,
	dictMap
} from '../../../app/variables';
import AngleRight from 'salt-icon/lib/AngleRight';
import DB from '../../../app/db';

const Item = React.createClass({
	handleListItemClick:function(){
		//pageSkip('static/officeding/forum/dist/index.html', "#/post/view/" + this.props.postId + '/' + this.props.checkStatus + '/' + this.props.isModerator + '/' + this.props.authorParent + '/' + this.props.isAuthor + '/mypost');
		location.hash = "#/post/view/" + this.props.postId + '/' + this.props.checkStatus + '/' + this.props.isModerator + '/' + this.props.authorParent + '/' + this.props.isAuthor + '/mypost';
	},

	handleReplyClick:function(){
		var placeholderComment;
		if(this.props.type=='2'){
			placeholderComment = "回复@"+this.props.authorName+"...";
			location.hash = 'post/reply/' + '0' + '/' + this.props.id + '/' + this.props.board_id + '/undefined/undefined/' + this.props.nowAuthor + '/' + '4' +'/'+ placeholderComment +'/' + '3';
		}
		if(this.props.type=='3'){
			placeholderComment = "回复@"+this.props.authorName+"...";
			location.hash = 'post/reply/' + '0' + '/' + this.props.postId + '/' + this.props.board_id + '/undefined/undefined/' + this.props.nowAuthor + '/' + '4'+'/'+ placeholderComment +'/' + '4/' + this.props.id;
		}
		
	},
	

	render: function() {
		var url=this.props.urlPrev;
		var imgUrl = '';
		if(this.props.image != null&&this.props.image != ''){
			imgUrl = url + this.props.image+'&token='+this.props.token;
		}
		return (
			<div>
			<VBox>
            <HBox vAlign="top" className="  t-PT24 t-BCf ">
            <Box className="t-PR16" style={{ marginTop: '-6px' }}>
            	{
	          	 (imgUrl!=null&&imgUrl!='')?<Avatar src={imgUrl} size={40} />: <Avatar name={this.props.authorName}  size={40} style={{ fontSize:12}}/>
	            }
            </Box>
            <Box className=" t-W100" >                                                                                  
			  <Box className="t-FC3 "><span > {this.props.authorName}</span><span className="t-FR t-FCddfontblue-40" >
			  <i className={this.props.boardDelete==0&&this.props.boardStatus==1&&this.props.typeStatus==1&&this.props.is_delete==0&&this.props.remindPageType != 1&&!this.props.blackListFlag? "iconfont icon-discribe t-FS14":"t-DN"} onClick={this.handleReplyClick.bind(this)}></i></span></Box>
              <HBox vAlign="center" className="t-FCddfontblue-40 t-PB8 t-FS12" onClick={this.handleListItemClick.bind(this)}>
                <Box className="t-MT6">
                 {this.props.createdDate}
              </Box>
              </HBox>
              <Box className="t-LH1_4 t-MB8" onClick={this.handleListItemClick.bind(this)}>
                <div className="t-FC3" dangerouslySetInnerHTML={{__html: this.props.content}}></div>
              </Box>
              <Box className=" t-R4" style={{background:'rgba(242,243,245,.6)'}} onClick={this.handleListItemClick.bind(this)}>
                <HBox>
                  <Box flex={1} className="t-FS14 t-LH1_4  t-PT10" style={{height:'38'}}>
				     <span className="t-FC9 t-FL t-ML16">{this.props.level}</span>
                     <p className="dd-message t-PL4 t-MR14 t-omit" dangerouslySetInnerHTML={{__html: this.props.title}}></p>
                  </Box>
                </HBox>
				<Box style={{ clear: 'both' }}></Box>
              </Box>
            </Box>
            </HBox>
            </VBox>
            </div>
		);
	}
});
export default class PageHome extends Component {

	constructor(props) {
		super(props);
		var hasBottomTab =  document.getElementById("hasBottomTab").value;
		let winHeight =getScrollHigh(0, 0, 0);
		var context = document.getElementById("context").value;
		var remindType = props.params.remindPage;
		this.state = {
			winHeight: winHeight,
			urlPrev: context + '/api/m/plugin/attachment/mobile/viewImage?fid=',
			remindType:remindType
		}

		dd.biz.navigation.setTitle({
      		title: "论坛动态",
		    onSuccess: function (result) {
		    },
     		 onFail: function () {
      		}
    	});

    }

	componentDidMount() {
		window.scrollTo(0,0);
	}

	beforeFetch(data, from) {
		data.rows = data.pageSize;
		data.limit = data.pageSize;
		data.remindPageType = this.state.remindType
		return data;
	}

	processData(data) {
		return data;
	}

	render() {
		var url=this.state.urlPrev;
		var token = document.getElementById("token").value;
		var imgUrl = '';
		if(this.state.image != null && this.state.image != '' && this.state.image != 'null'){
			imgUrl = url + this.state.image+'&token='+token;
		}
		let winHeightStyle = {
			height:this.state.winHeight
		};
		return (
			<div className="t-PT10 dd-t-list-wrap dd-bottom-border t-BCf">
	            <div style={winHeightStyle} >
		            <ScrollList
		               url={URLS.queryRemindList}
		               dataType="json"
		               pageSize={10}
		               ref="post_remind_ref"
		               beforeFetch={this.beforeFetch.bind(this)}
		               processData={this.processData.bind(this)}
		               noDataImage={nodataIcon}
		               currentPageKey="page"
		               fetchDataOnOpen={true}>
		            <Item urlPrev={this.state.urlPrev} token={token} />
		            </ScrollList>
            	</div>
            </div>
		);
	}
}